package com.zj.seckill.controller;

import com.zj.seckill.result.CodeMsg;
import com.zj.seckill.result.Result;
import com.zj.seckill.service.MiaoshaUserService;
import com.zj.seckill.util.ValidatorUtil;
import com.zj.seckill.vo.LoginVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.thymeleaf.util.StringUtils;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

/**
 * @author zhouji
 * @create 2021/4/5
 */

@Controller
@RequestMapping("/login")
@Slf4j
public class LoginController {

    @Autowired
    MiaoshaUserService miaoshaUserService;

    @RequestMapping("/toLogin")
   public String toLogin(){
       return "login";
   }

   @RequestMapping("/do_login")
   @ResponseBody
    public Result<String> doLogin(HttpServletResponse response,@Valid LoginVo loginVo){
       //登录
       String token= miaoshaUserService.login(response, loginVo);
       return Result.success(token);
    }

}
